home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT8 / WRCHAR.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  3.0 KB  |  87 lines

  1. ;-----------------------------------------------------------
  2. ;
  3. ;  Program WrChar ( Chapter 8 ) 
  4. ;
  5. ;  Procedure for writing a character+ attribute at the address: DH, DL
  6. ;
  7. ;  Author:  A.I.Sopin      VSU,     Voronezh, 1992
  8. ;
  9. ;  Input parameters:
  10. ;
  11. ;  AL - a character to be written
  12. ;
  13. ;  AH - attribute of a character
  14. ;
  15. ;  BH  - number of a video page (0, 1, 2, 3)
  16. ;
  17. ;  BL  - type of a video adapter (is determined using  VIDTYP)
  18. ;
  19. ;  DH  - line of a character (0 --- 49)
  20. ;
  21. ;  DL  - column of a character (0 --- 79)
  22. ;
  23. ;  CX  - quantity of characters to be written
  24. ;
  25. ;  ES  - segment address of a video buffer
  26. ;
  27. ;  The direct writing to vibeo buffer is used
  28. ;-----------------------------------------------------------
  29.  
  30. .MODEL  SMALL
  31. .CODE
  32. WRCHAR  PROC    FAR
  33.     PUBLIC  WRCHAR
  34.     push    ax                ;
  35.     push    bx                ;
  36.     push    cx                ;
  37.     push    dx                ;
  38.     push    si                ;
  39.     push    di                ;
  40.     push    es                ;
  41.     push    bp                ;
  42.     mov     bp,ax             ;  save character + attribute
  43.     mov     si,cx             ;  counter of characters being written
  44.     mov     CS:CGA,bl         ;  type of video adapter
  45. ;  Computation an address of character + attribute in the video buffer
  46.     mov     al,dh             ;  multiplier - line of a start of output
  47.     mov     cl,160            ;  multiplier =160
  48.     mul     cl                ;  compute offset of video buffer
  49.     xor     cx,cx             ;
  50.     mov     cl,dl             ;  add column of output
  51.     sal     cx,1              ;  *2
  52.     add     ax,cx             ;  compute offset of a character
  53.     mov     di,ax             ;
  54.     mov     bl,bh             ;  BL - number of video page
  55.     mov     cl,12             ;  number of shifts *4096
  56.     sal     bx,cl             ;  page number *4096
  57.     add     di,bx             ;  address taking offset into account
  58.     mov     cx,si             ;  counter of characters been written
  59. ;  External cycle of writing acharacter + attribute to video buffer
  60. Cycle0: cmp     CS:CGA,1          ;    CGA ?
  61.     jne     Write             ;  don't check for interference
  62.     mov     dx,3DAH           ;  status register
  63. ;  Waiting for completion of retrace
  64. Cycle1: in      al,dx             ;  read status register 
  65.     test    al,1              ;  is it retrace now  ?
  66.     jnz     Cycle1            ;  yes, wait for completion
  67. ;  Test , if writing is possible (to avoid interference)
  68. Cycle2: in      al,dx             ;  read status register
  69.     test    al,1              ;  is it retrace now (may we write)?
  70.     jz      Cycle2            ;  no, continue interrogation
  71. Write:  mov     ax,bp             ;  restore character + attribute
  72.     stosw                     ;  pass character + attribute
  73.     loop    Cycle0            ;  continue output
  74. ;  Restoring the registers been used and exit
  75.     pop     bp
  76.     pop     es
  77.     pop     di
  78.     pop     si
  79.     pop     dx
  80.     pop     cx
  81.     pop     bx
  82.     pop     ax
  83.     RETF
  84. CGA     DB      0                 ;  1 -  CGA indicator
  85. WRCHAR  ENDP
  86.     END
  87.